<?php
/*
 * DefinedFileToSoUI
 * 
 * @since 1.0 2014-9-1 by sutroon
 */
require 'Inc/incDbHead.php';
require 'Inc/incDefinedFileFunc.php';
require 'Data/Cur_DefinedFile.php';
?>
<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title>DefinedFileToSoUI</title>
        <style type='text/css'>
            body { font-size:12px;}
            table{width:100%; border: solid 1px #CCC; border-left:none; border-bottom: none;}
            th:first-child{width:30px;}
            .th-field {width:500px;}
            th, td { padding: 5px; border:solid 1px #CCC; border-right: none; border-top: none;}
            tr.tr-alt { background-color: #efefef;}
            a { text-decoration: none;}
            fieldset{ margin-bottom:10px; width:960px;}
            fieldset textarea { width:100%; height:300px;}
        </style>
        <script type="text/javascript" src="/Public/Script/jquery-1.11.1.min.js"></script>
    </head>
    <body>
        <?php
        // 显示数据库登录表单
        if (!$conn_info) {
            echoDbLoginForm();
        }
        // 全局菜单
        include 'Inc/incMenu.php';

        $table = isset($_GET['table']) ? $_GET['table'] : ''; // 获取当前选中的数据表名称
        // 显示所有数据表的下拉框
        $result = mysql_query('show tables;'); // 读取所有数据表 
        // 生成数据表下拉控件
        $str = '<div><select id="table-name" onchange="location.href=\'?table=\'+this.value"><option>请选择</option>';
        while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
            $str.='<option value="' . $row[0] . '"' . ($table && $row[0] == $table ? ' selected="selected"' : '') . '>' . $row[0] . '</option>';
        }
        $str.='</select><input type="button" value="Loginoff" onclick="location.href=\'?action=loginoff\'" /> <a href="SoProjectManager.php" target="_blank">[ProjMgr]</a></div>';
        echo $str;

        if ($table) {
            echo 'DefinedFileToSoUI: ' . $table . '<hr />';
            // form 2014-9-1 by sutroon
            echo '<fieldset><legend>Form</legend><textarea>';
            echo definedfile_to_formui_code($DATABASE_SET, $table);
            echo '</textarea></fieldset>';

            // table-list 2014-9-1 by sutroon
            echo '<fieldset><legend>Table or List</legend><textarea>';
            echo definedfile_to_tableui_code($DATABASE_SET, $table);
            echo '</textarea></fieldset>';

            // mvc-action 2014-9-2 by sutroon
            echo '<fieldset><legend>MVC-Action</legend><textarea>';
            echo definedfile_to_mvccontrol_code($DATABASE_SET, $table);
            echo '</textarea></fieldset>';
        }
        // 释放资源
        unset($db);
        ?>
        <script type="text/javascript">
            // fieldset标题点击收起或展开 2014-8-22 by sutroon
            $('legend').attr('title', '点击展开或收起').click(function() {
                $(this).next().toggle();
            })
        </script>
    </body>
</html>
